''========================================================
'' Autor: 		Luis Antonio Lara Capetillo
'' Fecha Creación: 	23/11/2012
'' Descripcion: 	Clase Componente ctlFUGridVehiculo
''========================================================

Public Class ctlFUGridVehiculo

  Inherits System.Web.UI.UserControl
    Public Event btnNidFormatoUnicoClicked As EventHandler

	Dim tablaAuxiliar As New DataTable

#Region "Propiedades"
  ''' <summary>
  ''' Obtiene o estable el valor Marca del TextBox txtMarca
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Marca() As String
    Get
      Return Me.txtMarca.Text
    End Get
    Set(value As String)
      Me.txtMarca.Text = value
    End Set
  End Property

  ''' <summary>
  ''' Obtiene o estable el valor Modelo del TextBox txtModelo
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Modelo() As String
    Get
      Return Me.txtModelo.Text
    End Get
    Set(value As String)
      Me.txtModelo.Text = value
    End Set
  End Property

  ''' <summary>
  ''' Obtiene o estable el valor Vin del TextBox txtVin
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Vin() As String
    Get
      Return Me.txtVin.Text
    End Get
    Set(value As String)
      Me.txtVin.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene o estable el valor Folio del TextBox txtFolio
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Folio() As String
    Get
      Return Me.txtFolio.Text
    End Get
    Set(value As String)
      Me.txtFolio.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene o establece el valor Fecha_Vigencia_Poliza del TextBox txtFecha_Vigencia_Poliza
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Fecha_Vigencia_Poliza() As String
    Get
      Return Me.txtFecha_Vigencia_Poliza.Text
    End Get
    Set(value As String)
      Me.txtFecha_Vigencia_Poliza.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene o estable el valor Poliza del TextBox txtPoliza
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Poliza() As String
    Get
      Return Me.txtPoliza.Text
    End Get
    Set(value As String)
      Me.txtPoliza.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene o estable el valor Placa del TextBox txtPlaca
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Placa() As String
    Get
      Return Me.txtPlaca.Text
    End Get
    Set(value As String)
      Me.txtPlaca.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene o estable el valor Color del TextBox txtColor
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Color() As String
    Get
      Return Me.txtColor.Text
    End Get
    Set(value As String)
      Me.txtColor.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene o estable el valor Observaciones del TextBox txtObservaciones
  ''' </summary>
  ''' <value>valor tipo String</value>
  ''' <returns>valor tipo String</returns>
  ''' <remarks></remarks>
  Public Property Observaciones() As String
    Get
      Return Me.txtObservaciones.Text
    End Get
    Set(value As String)
      Me.txtObservaciones.Text = value
    End Set
  End Property

   ''' <summary>
  ''' Obtiene la tabla con la informacion del gridview
  ''' </summary>
  ''' <value></value>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public ReadOnly Property TablaDatos() As DataTable
    Get
      ObtenerFilasAgregadas()
      Return tablaAuxiliar
    End Get
  End Property

  ''' <summary>
  ''' Habilita o Desabilita el Control para Edicion
  ''' </summary>
  ''' <value>True o False</value>
  ''' <remarks></remarks>
  Public WriteOnly Property Enabled() As Boolean
    Set(value As Boolean)
	  btnNidFormatoUnico.Enabled=value
      txtMarca.Enabled=value
      txtModelo.Enabled=value
      txtVin.Enabled=value
      txtFolio.Enabled=value
      txtFecha_Vigencia_Poliza.Enabled=value
      txtPoliza.Enabled=value
      txtPlaca.Enabled=value
      txtColor.Enabled=value
      txtObservaciones.Enabled=value
      gdvNid.Enabled=value
      
    End Set
  End Property

  ''' <summary>
  ''' Habilita o Desabilita el Control para solo lectura
  ''' </summary>
  ''' <value>True o False</value>
  ''' <remarks>ReadOnly</remarks>
  Public WriteOnly Property Lectura() As Boolean
    Set(value As Boolean)
	  btnNidFormatoUnico.ReadOnly=value
      txtMarca.ReadOnly=value
      txtModelo.ReadOnly=value
      txtVin.ReadOnly=value
      txtFolio.ReadOnly=value
      txtFecha_Vigencia_Poliza.ReadOnly=value
      txtPoliza.ReadOnly=value
      txtPlaca.ReadOnly=value
      txtColor.ReadOnly=value
      txtObservaciones.ReadOnly=value
      gdvNid.ReadOnly=value
      
    End Set
  End Property


#End Region
#Region "Eventos"
   Protected Sub btnNidFormatoUnico_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles btnNidFormatoUnico.Click
    OnbtnNidFormatoUnicoClick(sender)
  End Sub

   ''' <summary>
  ''' Evento que se genera cuando se da clic a cualquier boton del gdvNid
  ''' </summary>
  ''' <param name="sender"></param>
  ''' <param name="e"></param>
  ''' <remarks></remarks>
  Protected Sub gdvNid_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    Dim index As Integer
	index = Convert.ToInt32(e.CommandArgument)
    If e.CommandName = "Editar" Then
      'Codigo para editar
    End If
    If e.CommandName = "Copiar" Then
      'Codigo para Copiar
    End If
    If e.CommandName = "Eliminar" Then
      ObtenerFilasAgregadas()
      tablaAuxiliar.Rows(index).Delete()
      gdvDatos.DataSource = tablaAuxiliar
      gdvDatos.DataBind()
    End If
  End Sub
  ''' <summary>
  ''' Evento para ocultar valor en el gridview
  ''' </summary>
  ''' <param name="sender"></param>
  ''' <param name="e"></param>
  ''' <remarks></remarks>
  Protected Sub gdvNid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvNid.RowDataBound
    Try
      'Se ocultan las columnas que no se requiere ver pero conservar su valor
	  'ejemplo: e.Row.Cells(0).Visible = False
      
    Catch ex As Exception

    End Try
  End Sub

#End Region
#Region "Metodos"
   Protected Overridable Sub OnbtnNidFormatoUnicoClick(ByVal sender As Object)
    RaiseEvent btnNidFormatoUnicoClicked(sender, New EventArgs)
  End Sub

   ''' <summary>
  ''' Metodo para obtener las filas del GridView
  ''' </summary>
  ''' <remarks></remarks>
  Private Sub ObtenerFilasAgregadas()
    tablaAuxiliar = crearTabla()
    For i As Integer = 0 To gdvNid.Rows.Count - 1
      Dim NuevaFila As DataRow = tablaAuxiliar.NewRow()
	  ?TablaFila
      'ejemplo: NuevaFila("nombreColumna") = gdvDatos.Rows(i).Cells.Item(0).Text
      
      tablaAuxiliar.Rows.Add(NuevaFila)
    Next
  End Sub
  ''' <summary>
  ''' Metodo para crear una tabla con las columnas del gridView
  ''' </summary>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Private Function crearTabla() As DataTable
    Dim tabla As New DataTable
    Dim Columna As DataColumn
	'Ejemplo:
    'Columna = New DataColumn()
    'Columna.DataType = System.Type.GetType("System.String")
    'Columna.ColumnName = "NIDEMBALAJE"
    'Columna.DefaultValue = ""
    'tabla.Columns.Add(Columna)
	?TablaColumnas
	
    Return tabla
  End Function

  ''' <summary>
  ''' Metodo para asignar los datos al componente ctlTurismo
  ''' </summary>
  ''' <param name="tablaDatos">DataTable donde se obtienen los datos</param>
  ''' <remarks></remarks>
  Public Sub AsignarDatos(ByVal tablaDatos As DataTable)
    Me.txtMarca.Text= tablaDatos.Rows(0)("Marca").ToString
    Me.txtModelo.Text= tablaDatos.Rows(0)("Modelo").ToString
    Me.txtVin.Text= tablaDatos.Rows(0)("Vin").ToString
    Me.txtFolio.Text= tablaDatos.Rows(0)("Folio").ToString
    Me.txtFecha_Vigencia_Poliza.Text= tablaDatos.Rows(0)("Fecha_Vigencia_Poliza").ToString
    Me.txtPoliza.Text= tablaDatos.Rows(0)("Poliza").ToString
    Me.txtPlaca.Text= tablaDatos.Rows(0)("Placa").ToString
    Me.txtColor.Text= tablaDatos.Rows(0)("Color").ToString
    Me.txtObservaciones.Text= tablaDatos.Rows(0)("Observaciones").ToString
    
  End Sub

   ''' <summary>
  ''' Metodo para llenar el gdvNid con datos de la table
  ''' </summary>
  ''' <param name="tabla">tabla donde se obtienen los datos</param>
  ''' <remarks></remarks>
  Public Sub llenargdvNid(ByVal tabla As DataTable)
    Me.gdvNid.DataSource = tabla
    Me.gdvNid.DataBind()
  End Sub
  ''' <summary>
  ''' Metodo para Seleccionar la pagina de el gdvNid
  ''' </summary>
  ''' <param name="e">es un evento de tipo GridViewPageEventArgs</param>
  ''' <remarks></remarks>
  Public Sub SelecPagegdvNid(ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
    Me.gdvNid.PageIndex = e.NewPageIndex
    Me.gdvNid.DataBind()
  End Sub


#End Region
End Class
